package pingce.share.model;

import java.io.Serializable;

import edu.stanford.nlp.trees.Tree;
import pingce.share.util.*;

/**
 * 存放每个子句的结果
 * @author ucai
 *
 */
public class SubSentenceResult implements Serializable {
	private static final long serialVersionUID = 677940664348263439L;
	private int begin;
	private int end;
	private String rawText;
	/**
	 * SplitResult是每个子句的分词结果
	 * Tree是stanford parser 句法分析之后的结果 
	 */
	private SplitResult splitResult;
	private Tree parseResult;
	/**
	 * 子句的类型，具体参看WrappedSplitter的注释
	 */
	private int type = WrappedSplitter.NORMAL;

	public SubSentenceResult(int begin, PairValue pv, SentenceProcessor sp){
		String rawText = pv.getBasic();
		int type = Integer.parseInt(pv.getAttach());
		this.begin = begin;
		this.end = begin + rawText.length() - 1;
		this.rawText = rawText;
		this.type = type;
		System.out.println("this.type=" + type);
		if(type != WrappedSplitter.NORMAL){// if it's not normal clause, then don't parse
			this.splitResult = null;
			this.parseResult = null;
		}else{
			String resultWithPOS = sp.splitter.Split(rawText, true);
			this.splitResult = new SplitResult(resultWithPOS, begin);
			this.parseResult = sp.getParsedTreeRaw(
					splitResult.getNoPosArrayResult(), rawText);
		}
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("begin = " + this.begin + "\tend=" + this.end + "\ttype=" + this.type);
		sb.append("\n" + this.rawText);
		if(splitResult == null || parseResult == null)
			sb.append("not to parse");
		else{
			sb.append("\nsplitResult:" + this.splitResult.toString());
			sb.append("\nparseResult=\n" + this.parseResult.pennString());
		}
		return sb.toString();
	}

	public int getBegin() {
		return begin;
	}

	public void setBegin(int begin) {
		this.begin = begin;
	}

	public int getEnd() {
		return end;
	}

	public void setEnd(int end) {
		this.end = end;
	}

	public String getRawText() {
		return rawText;
	}

	public void setRawText(String rawText) {
		this.rawText = rawText;
	}

	public SplitResult getSplitResult() {
		return splitResult;
	}

	public void setSplitResult(SplitResult splitResult) {
		this.splitResult = splitResult;
	}

	public Tree getParseResult() {
		return parseResult;
	}

	public void setParseResult(Tree parseResult) {
		this.parseResult = parseResult;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
}
